package apiSecurity;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.Ordered;

/**
 * @author zhanglinfeng
 * @date create in 2023/7/27 16:20
 */
@Aspect
public class ApiSecurityAspect implements Ordered {
    @Override
    public int getOrder() {
        return 5;
    }

    @Pointcut("@annotation(apiSecurity.ApiSecurity)")
    public void pointcut() {
    }

    @Around("pointcut()&&@annotation(apiSecurity)")
    public Object doAspect(ProceedingJoinPoint joinPoint, ApiSecurity apiSecurity) throws Throwable {
        //响应数据
        Object returnObject;
        //解密请求参数
        boolean decryptRequest = apiSecurity.decryptRequest();
        //加密响应数据
        boolean encryptResponse = apiSecurity.encryptResponse();
        Object[] args = joinPoint.getArgs();
        //解密请求参数
        if (decryptRequest) {
            for (int i = 0; i < args.length; i++) {
                //TODO 解密

            }
        }
        returnObject = joinPoint.proceed(args);
        //加密响应数据
        if (encryptResponse) {
            //TODO
        }
        return returnObject;
    }


}
